package com.sskj.cndragon.presenter;

import com.lzy.okgo.model.Response;
import com.shizhefei.view.coolrefreshview.CoolRefreshView;
import com.sskj.cndragon.bean.LastTimeBean;
import com.sskj.cndragon.bean.OrderBuyListBean;
import com.sskj.cndragon.http.HttpConfig;
import com.sskj.cndragon.ui.activity.OrderSellDetailActivity;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.http.JsonCallBack;


public class OrderSellDetailActivityPresenter extends BasePresenter<OrderSellDetailActivity> {
    public void getSellDetailMsg(String pollID, String orderID, CoolRefreshView coolRefreshView) {
        httpService.getSellDetailMsg(pollID, orderID)
                .tag(this)
                .execute(new JsonCallBack<HttpData<OrderBuyListBean.OrderBuyBean>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<OrderBuyListBean.OrderBuyBean>> response) {
                        if (coolRefreshView != null && coolRefreshView.isRefreshing()) {
                            coolRefreshView.setRefreshing(false);
                        }
                        HttpData<OrderBuyListBean.OrderBuyBean> body = response.body();
                        if (body.getStatus() == HttpConfig.OK) {
                            mView.getSellDetailMsgOK(body.getData());
                        } else {
                            ToastUtil.showShort(body.getMsg());
                        }
                    }
                });
    }

    public void getLastTime(int countType) {
        httpService.getLastTime()
                .tag(this)
                .execute(new JsonCallBack<HttpData<LastTimeBean>>() {
                    @Override
                    public void onSuccess(Response<HttpData<LastTimeBean>> response) {
                        HttpData<LastTimeBean> body = response.body();
                        if (body.getStatus() == HttpConfig.OK) {
                            mView.getLastTimeOK(body.getData(), countType);
                        }
                    }
                });
    }


    public void shensu(String sellStockUserId, String buyStockUserId, String swiftNo, String msg, String orderID) {
        httpService.shensu(sellStockUserId, buyStockUserId, swiftNo, msg, orderID)
                .tag(this)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData body = response.body();
                        ToastUtil.showShort(body.getMsg());
                    }
                });
    }

    public void confirmPay(String orderID) {
        httpService.confirmPay(orderID)
                .tag(this)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData body = response.body();
                        ToastUtil.showShort(body.getMsg());
                        if (body.getStatus() == HttpConfig.OK) {
                            mView.confirmOK();
                        }

                    }
                });
    }
}
